package com.ruoyi.news.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.news.domain.XxcCash;
import com.ruoyi.news.domain.XxcWallet;
import com.ruoyi.news.mapper.XxcCashMapper;
import com.ruoyi.news.service.IXxcCashService;
import com.ruoyi.news.service.IXxcWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 小程序-提现Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-20
 */
@Service
public class XxcCashServiceImpl implements IXxcCashService
{
    @Autowired
    private XxcCashMapper xxcCashMapper;

    @Autowired
    private IXxcWalletService xxcWalletService;

    /**
     * 查询小程序-提现
     * 
     * @param id 小程序-提现主键
     * @return 小程序-提现
     */
    @Override
    public XxcCash selectXxcCashById(String id)
    {
        return xxcCashMapper.selectXxcCashById(id);
    }

    /**
     * 查询小程序-提现列表
     * 
     * @param xxcCash 小程序-提现
     * @return 小程序-提现
     */
    @Override
    public List<XxcCash> selectXxcCashList(XxcCash xxcCash)
    {
        return xxcCashMapper.selectXxcCashList(xxcCash);
    }

    /**
     * 新增小程序-提现
     * 
     * @param xxcCash 小程序-提现
     * @return 结果
     */
    @Override
    public int insertXxcCash(XxcCash xxcCash)
    {
        xxcCash.setCreateTime(DateUtils.getNowDate());
        XxcWallet xxcWallet = xxcWalletService.selectXxcWalletByUserId( xxcCash.getTakeUserId() );
        BigDecimal moeny = new BigDecimal(xxcCash.getMoney());
        xxcWallet.setCashE( moeny );
        xxcWallet.setYuE(xxcWallet.getYuE().subtract(moeny));
        int flag = xxcWalletService.updateXxcWallet(xxcWallet);
        if(flag > 0) {
            return xxcCashMapper.insertXxcCash(xxcCash);
        }
        return 0;
    }

    /**
     * 修改小程序-提现
     * 
     * @param xxcCash 小程序-提现
     * @return 结果
     */
    @Override
    public int updateXxcCash(XxcCash xxcCash)
    {
        xxcCash.setUpdateTime(DateUtils.getNowDate());
        return xxcCashMapper.updateXxcCash(xxcCash);
    }

    /**
     * 批量删除小程序-提现
     * 
     * @param ids 需要删除的小程序-提现主键
     * @return 结果
     */
    @Override
    public int deleteXxcCashByIds(String[] ids)
    {
        return xxcCashMapper.deleteXxcCashByIds(ids);
    }

    /**
     * 删除小程序-提现信息
     * 
     * @param id 小程序-提现主键
     * @return 结果
     */
    @Override
    public int deleteXxcCashById(String id)
    {
        return xxcCashMapper.deleteXxcCashById(id);
    }
}
